<template>
  <div>
     <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>数据统计</el-breadcrumb-item>
        <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card style="margin-top:30px">
      <div ref="box" style="width: 100%; height: 400px"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import {getDataReportsApi} from '../../http/api'
console.log(echarts)
export default {
  name: 'reports',
  data() {
    return {
      myChart: null,
      preData: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            } 
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  mounted() {
    this.renderChart()
    window.addEventListener('resize', this.myChart.resize)
  },
  methods: {
    async renderChart() {
      const chartDom = this.$refs.box
      this.myChart = echarts.init(chartDom)
      const res = await getDataReportsApi()

      console.log('图表后台：', res)
      const mergeData = { ...this.preData, ...res }
      const options = mergeData

      this.myChart.setOption(options)
    }
  }
}
</script>

<style lang="scss" scoped></style>